package com.scm.service.impl;

import java.util.Collections;
import java.util.List;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.scm.common.core.domain.entity.SysUser;
import com.scm.common.core.page.PageDomain;
import com.scm.common.utils.DateUtils;
import com.scm.common.utils.StringUtils;
import com.scm.persist.model.ScmSupplyQuotation;
import com.scm.persist.model.ScmSupplyQuotationExample;
import com.scm.persist.mybatis.ScmSupplyQuotationMapper;
import com.scm.service.IScmSupplyQuotationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.scm.common.core.text.Convert;

/**
 * 询价单Service业务层处理
 *
 * @author reptilemanager
 * @date 2024-05-17
 */
@Service
public class ScmSupplyQuotationServiceImpl implements IScmSupplyQuotationService
{
    @Autowired
    private ScmSupplyQuotationMapper scmSupplyQuotationMapper;

    /**
     * 查询询价单
     *
     * @param id 询价单主键
     * @return 询价单
     */
    @Override
    public ScmSupplyQuotation selectScmSupplyQuotationById(Long id)
    {
        return scmSupplyQuotationMapper.selectByPrimaryKey(id);
    }

    /**
     * 查询询价单列表
     *
     * @param scmSupplyQuotation 询价单
     * @return 询价单
     */
    @Override
    public List<ScmSupplyQuotation> selectScmSupplyQuotationList(ScmSupplyQuotation scmSupplyQuotation, SysUser sysUser)
    {
        ScmSupplyQuotationExample example = new ScmSupplyQuotationExample();
        ScmSupplyQuotationExample.Criteria criteria = example.createCriteria();
        if(StringUtils.isNotBlank(scmSupplyQuotation.getBillNo())){
            criteria.andBillNoEqualTo(scmSupplyQuotation.getBillNo());
        }
        if(StringUtils.isNotBlank(scmSupplyQuotation.getSubject())){
            criteria.andSubjectEqualTo(scmSupplyQuotation.getSubject());
        }
        criteria.andTenantIdEqualTo(sysUser.getTenantId());
        return scmSupplyQuotationMapper.selectByExample(example);
    }


    @Override
    public List<ScmSupplyQuotation> selectScmSupplyQuotationList(Long tenantId, ScmSupplyQuotation scmSupplyQuotation, PageDomain pageDomain) {

        ScmSupplyQuotationExample example = new ScmSupplyQuotationExample();
        ScmSupplyQuotationExample.Criteria criteria = example.createCriteria();
        if(StringUtils.isNotBlank(scmSupplyQuotation.getBillNo())){
            criteria.andBillNoEqualTo(scmSupplyQuotation.getBillNo());
        }
        if(StringUtils.isNotBlank(scmSupplyQuotation.getSubject())){
            criteria.andSubjectEqualTo(scmSupplyQuotation.getSubject());
        }
        PageHelper.startPage(pageDomain.getPageNum(), pageDomain.getPageSize());
        return scmSupplyQuotationMapper.selectByExample(example);
    }

    /**
     * 新增询价单
     *
     * @param scmSupplyQuotation 询价单
     * @return 结果
     */
    @Override
    public int insertScmSupplyQuotation(ScmSupplyQuotation scmSupplyQuotation)
    {
        scmSupplyQuotation.setCreateTime(System.currentTimeMillis());
        return scmSupplyQuotationMapper.insertSelective(scmSupplyQuotation);
    }

    /**
     * 修改询价单
     *
     * @param scmSupplyQuotation 询价单
     * @return 结果
     */
    @Override
    public int updateScmSupplyQuotation(ScmSupplyQuotation scmSupplyQuotation)
    {
        scmSupplyQuotation.setUpdateTime(System.currentTimeMillis());
        return scmSupplyQuotationMapper.updateByPrimaryKey(scmSupplyQuotation);
    }

    /**
     * 批量删除询价单
     *
     * @param ids 需要删除的询价单主键
     * @return 结果
     */
    @Override
    public int deleteScmSupplyQuotationByIds(List<Long> ids)
    {

        ScmSupplyQuotationExample example = new ScmSupplyQuotationExample();
        ScmSupplyQuotationExample.Criteria criteria = example.createCriteria();
        criteria.andIdIn(ids);
        return scmSupplyQuotationMapper.deleteByExample(example);
    }

    /**
     * 删除询价单信息
     *
     * @param id 询价单主键
     * @return 结果
     */
    @Override
    public int deleteScmSupplyQuotationById(Long id)
    {
        return scmSupplyQuotationMapper.deleteByPrimaryKey(id);
    }
}
